package com.muyu.vehicle.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.muyu.vehicle.process.SynchronizeFenceInfoThread;
import com.muyu.vehicle.process.ThreadPool;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import com.vehicle.common.log.annotation.Log;
import com.vehicle.common.log.enums.BusinessType;
import com.vehicle.common.security.annotation.PreAuthorize;
import com.muyu.vehicle.domain.VehicleFence;
import com.muyu.vehicle.service.IVehicleFenceService;
import com.vehicle.common.core.web.controller.BaseController;
import com.vehicle.common.core.web.domain.AjaxResult;
import com.vehicle.common.core.utils.poi.ExcelUtil;
import com.vehicle.common.core.web.page.TableDataInfo;

/**
 * 电子围栏Controller
 *
 * @author muyu
 * @date 2021-09-04
 */
@RestController
@RequestMapping("/fence")
public class VehicleFenceController extends BaseController
{
    @Autowired
    private IVehicleFenceService vehicleFenceService;

    @Autowired
    private RedisTemplate<String , String> redisTemplate;

    /**
     * 查询电子围栏列表
     */
    @PreAuthorize(hasPermi = "vehicle:fence:list")
    @GetMapping("/list")
    public TableDataInfo list(VehicleFence vehicleFence)
    {
        startPage();
        List<VehicleFence> list = vehicleFenceService.selectVehicleFenceList(vehicleFence);
        return getDataTable(list);
    }

    /**
     * 导出电子围栏列表
     */
    @PreAuthorize(hasPermi = "vehicle:fence:export")
    @Log(title = "电子围栏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VehicleFence vehicleFence) throws IOException
    {
        List<VehicleFence> list = vehicleFenceService.selectVehicleFenceList(vehicleFence);
        ExcelUtil<VehicleFence> util = new ExcelUtil<VehicleFence>(VehicleFence.class);
        util.exportExcel(response, list, "电子围栏数据");
    }

    /**
     * 获取电子围栏详细信息
     */
    @PreAuthorize(hasPermi = "vehicle:fence:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(vehicleFenceService.selectVehicleFenceById(id));
    }

    /**
     * 新增电子围栏
     */
    @PreAuthorize(hasPermi = "vehicle:fence:add")
    @Log(title = "电子围栏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehicleFence vehicleFence)
    {
        return toAjax(vehicleFenceService.insertVehicleFence(vehicleFence));
    }

    /**
     * 修改电子围栏
     */
    @PreAuthorize(hasPermi = "vehicle:fence:edit")
    @Log(title = "电子围栏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehicleFence vehicleFence)
    {
        return toAjax(vehicleFenceService.updateVehicleFence(vehicleFence));
    }

    /**
     * 删除电子围栏
     */
    @PreAuthorize(hasPermi = "vehicle:fence:remove")
    @Log(title = "电子围栏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(vehicleFenceService.deleteVehicleFenceByIds(ids));
    }



    /**
     * 获取电子围栏详细信息
     */
    @PreAuthorize(hasPermi = "vehicle:fence:query")
    @GetMapping(value = "/path/{id}")
    public AjaxResult getFencePath(@PathVariable("id") String id)
    {
        return AjaxResult.success("操作成功",vehicleFenceService.selectVehicleFencePathById(id));
    }
    /**
     * 获取电子围栏详细信息
     */
    @PreAuthorize(hasPermi = "vehicle:fence:query")
    @PostMapping(value = "/path")
    public AjaxResult saveFencePath(@RequestBody VehicleFence vehicleFence)
    {
        vehicleFenceService.saveFencePath(vehicleFence.getId() , vehicleFence.getPath());
        return AjaxResult.success();
    }

}
